<?php
/**
 * The control file of blog module of ZenTaoPHP.
 *
 * The author disclaims copyright to this source code.  In place of
 * a legal notice, here is a blessing:
 * 
 *  May you do good and not evil.
 *  May you find forgiveness for yourself and forgive others.
 *  May you share freely, never taking more than you give.
 */
class overview extends control
{
    /**
     * The construct function.
     * 
     * @access public
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
        $this->app->loadLang('index');
        if(!isset($_SESSION['username'])){
          $this->locate($this->createLink('index','login'));
        }
        $this->updateopt=$this->loadModel('updateopt');
    }
    
    public function overview($recTotal = 0, $recPerPage = 20, $pageID = 0,
        $key_word='',$type_id='all',$area_id='all',$unit_id='all',$source_status='all',$ipv6_status='all')
    {
		$this->view->title    = '网站状态统计-IPv6网站升级';
    	//动态加载css
    	$this->view->cssload =array('theme/default/css/report_alarm_fault.css',
    	                             'theme/default/css/style/cupertino/jquery-ui-1.7.2.custom.css');
    	$this->view->jsload=array('scripts/jquery-ui-1.7.2.custom.min.js',
    	                          'scripts/timepicker.js',
    	                           'boot-popover.js' 
    	                           );
    	//得到所有网站类型
    	$this->view->type_info=$this->updateopt->get_type_info();
    	//得到所有网站区域
    	$where_area=new stdClass();
    	$where_area->reid=0;
    	$this->view->area_info=$this->updateopt->get_area_info(null,$where_area);
    	//得到所有单位
    	$this->view->unit_info=$this->updateopt->get_unit_info();
    	
    	
        $this->app->loadClass('pager');
        $pager = new pager($recTotal, $recPerPage, $pageID);
        
        $where=new stdClass();
        $where->key_word=$key_word;
        $where->type_id=$type_id;
        $where->area_id=$area_id;
        $where->unit_id=$unit_id;
        $where->source_status=$source_status;
        $where->ipv6_status=$ipv6_status;
        
        //var_dump($this->overview->get_sites_info($pager,$where));
        $this->view->sites_info_list = $this->overview->get_sites_info($pager,$where);
        $this->view->pager    = $pager;
        $this->display();
    }
    
    
    //得到报警率
    public function get_info_prob(){
      $info=array();
      $where="action=1 and vflag=1";//提示
	  $num1=$this->overview->get_alarm_info_total($where);
	  $num11=$this->overview->get_alarm_info_total('action=1');
	  	
	  $where="action=2 and vflag=1";//重启
	  $num2=$this->overview->get_alarm_info_total($where);
	  $num22=$this->overview->get_alarm_info_total('action=2');
	  	
	  $where="action=3 and vflag=1";//关机
	  $num3=$this->overview->get_alarm_info_total($where);
	  $num33=$this->overview->get_alarm_info_total('action=3');
	  
	  $info[]=sprintf("%.2f",($num3/$num33)*100);
	  $info[]=sprintf("%.2f",($num1/$num11)*100);
	  $info[]=sprintf("%.2f",($num2/$num22)*100);
	  echo json_encode($info);
    }
    /**
     * 得到没有查看的报警信息条数
     */
    public function get_alarm_info_total(){
       $where='vflag=0';
       $num=$this->overview->get_alarm_info_total($where);
       echo $num;
    }

}
